package service.impl;

import service.AcademicScoresService;
import entity.AcademicScores;
import mapper.AcademicScoresMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AcademicScoresImpl implements AcademicScoresService {

    @Autowired
    private AcademicScoresMapper mapper;

    @Override
    public AcademicScores getById(Integer id) {
        return mapper.selectById(id);
    }

    @Override
    public List<AcademicScores> getAll() {
        return mapper.selectAll();
    }

    @Override
    public List<AcademicScores> getByStudentId(Integer sid) {
        return mapper.selectByStudentId(sid);
    }

    @Override
    public int create(AcademicScores s) {
        // 确保 isDegreeCourse 不为 null
        if (s.getIsDegreeCourse() == null) {
            s.setIsDegreeCourse(true); // 默认为学位课
        }

        return mapper.insert(s);
    }

    @Override
    public int update(AcademicScores s) {
        // 确保 isDegreeCourse 不为 null
        if (s.getIsDegreeCourse() == null) {
            s.setIsDegreeCourse(true); // 默认为学位课
        }

        return mapper.update(s);
    }

    @Override
    public int delete(Integer id) {
        return mapper.delete(id);
    }
}
